<template>

  <el-container class="container">
    <el-header class="header" style="height:70px">
     <!-- 折叠按钮 -->
        <div class="collapse-btn" @click="collapseChage">
            <i v-if="!collapse" class="el-icon-s-fold"></i>
            <i v-else class="el-icon-s-unfold"></i>
        </div>
          <div class="logo">餐厅点餐系统</div>


           <div class="header-right">
            <div class="header-user-con">
                <!-- 全屏显示 -->
                <div class="btn-fullscreen" @click="handleFullScreen">
                    <el-tooltip effect="dark" :content="fullscreen?`取消全屏`:`全屏`" placement="bottom">
                        <i class="el-icon-rank"></i>
                    </el-tooltip>
                </div>
                <!-- 消息中心 -->
                <div class="btn-bell">
                    <el-tooltip
                        effect="dark"
                        :content="message?`有${message}条未读消息`:`消息中心`"
                        placement="bottom"
                    >
                        <router-link to="/tabs">
                            <i class="el-icon-bell"></i>
                        </router-link>
                    </el-tooltip>
                    <span class="btn-bell-badge" v-if="message"></span>
                </div>
                <!-- 用户头像 -->
                <div class="user-avator">
                    <img src="../../assets/images/img.jpg" />
                </div>
                <!-- 用户名下拉菜单 -->
                <el-dropdown class="user-name" trigger="click" @command="handleCommand">
                    <span class="el-dropdown-link">
                        {{username}}
                        <i class="el-icon-caret-bottom"></i>
                    </span>
                    <el-dropdown-menu slot="dropdown">
                        <a href="https://github.com/lin-xin/vue-manage-system" target="_blank">
                            <el-dropdown-item>项目仓库</el-dropdown-item>
                        </a>
                        <el-dropdown-item divided command="loginout">退出登录</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </div>
        </div>
    </el-header>
    <el-container class="container2">
      <el-aside >
        
        <el-menu background-color="#0a2c1ee0" text-color="#fff"
          style="height:90vh"
          active-text-color="#ffff99"
          class="sidebar-el-menu"
            :default-active="onRoutes"
            
            :collapse="collapse"          
            unique-opened
           router


           
        >
        <el-submenu 
          default-active="this.$router.path" 
          router mode="horizontal"
          index="/customer">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span style="font-size:18px">我的订单</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/unfinished_booking" style="font-size:15px">进行中的订单</el-menu-item>
              <el-menu-item index="/finished_booking" style="font-size:15px">历史订单</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-menu-item index="/customer_menu">
            <i class="el-icon-document"></i>
            <span slot="title" style="font-size:18px">查看菜单</span>
          </el-menu-item>
          <el-menu-item index="/change_password">
            <i class="el-icon-setting"></i>
            <span slot="title" style="font-size:18px">修改密码</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
      <el-main> 
              <div class="wrapper">
          <div class="content-box" :class="{'content-collapse':collapse}">
            
            <div class="content">
                <transition name="move" mode="out-in">
                    <keep-alive :include="tagsList">
                        <router-view></router-view>
                    </keep-alive>
                </transition>
                <el-backtop target=".content"></el-backtop>
            </div>
            </div>
        </div>
      </el-main>
      </el-container>
    </el-container>
  </el-container>
</template>
 
<script>
import bus from '../../components/bus';
export default {
  
   data() {
      
      return {
      collapse: false,

      }
    },

   mounted() {
             if (document.body.clientWidth < 1500) {
            this.collapseChage();
        }
    let _this = this; // 声明一个变量指向Vue实例this，保证作用域一致
    this.timer = setInterval(() => {
      _this.date = new Date(); // 修改数据date
    }, 1000)
  },
  beforeDestroy() {
    if (this.timer) {
      clearInterval(this.timer); // 在Vue实例销毁前，清除我们的定时器
    }
  },

  methods: {
        computed: {
        onRoutes() {
            return this.$route.path.replace('/', '');
        }
    },
    
            // 用户名下拉菜单选择事件
        handleCommand(command) {
            if (command == 'loginout') {
                localStorage.removeItem('ms_username');
                this.$router.push('/login');
            }
        },
            // 侧边栏折叠
        collapseChage() {
            this.collapse = !this.collapse;
            bus.$emit('collapse', this.collapse);
        },
         // 全屏事件
        handleFullScreen() {
            let element = document.documentElement;
            if (this.fullscreen) {
                if (document.exitFullscreen) {
                    document.exitFullscreen();
                } else if (document.webkitCancelFullScreen) {
                    document.webkitCancelFullScreen();
                } else if (document.mozCancelFullScreen) {
                    document.mozCancelFullScreen();
                } else if (document.msExitFullscreen) {
                    document.msExitFullscreen();
                }
            } else {
                if (element.requestFullscreen) {
                    element.requestFullscreen();
                } else if (element.webkitRequestFullScreen) {
                    element.webkitRequestFullScreen();
                } else if (element.mozRequestFullScreen) {
                    element.mozRequestFullScreen();
                } else if (element.msRequestFullscreen) {
                    // IE11
                    element.msRequestFullscreen();
                }
            }
            this.fullscreen = !this.fullscreen;
        },
created() {
          // 通过 Event Bus 进行组件间通信，来折叠侧边栏
        bus.$on('collapse', msg => {
            this.collapse = msg;
            bus.$emit('collapse-content', msg);
        });


        bus.$on('collapse-content', msg => {
            this.collapse = msg;
        });

        // 只有在标签页列表里的页面才使用keep-alive，即关闭标签之后就不保存到内存中了。
        bus.$on('tags', msg => {
            let arr = [];
            for (let i = 0, len = msg.length; i < len; i++) {
                msg[i].name && arr.push(msg[i].name);
            }
            this.tagsList = arr;
        });
    },
    //退出
    logout() {
      this.$confirm("退出登录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$router.push({ path: "/login" });
      });
    },
  },
};
</script>
<style scoped>

.wrapper{
  position:center
}
.container {
  height: 100vh;

  /* min-width: 100%;#0c1c35e0 */
  min-height: 600px;
  overflow: hidden;
  background-color: rgba(252, 246, 214, 0.534);
  
}
.container2{
  height: 100%;
}
.header {
  background-color: #0a2c1ee0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 28px;
  color:#fff
}

.headerlogo {
  line-height: 60px;
  margin-top: 10px;
}
.rightsection {
  line-height: 60px;
  text-align: center;
}
.iconfont{
  margin-right: 10px;
}
.toggle-button{
  background-color: #408dc0;
  font-size: 10px;
  line-height: 24px;
  color:cornsilk;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
.collapse-btn {
    float: left;
    padding: 0 21px;
    cursor: pointer;
    line-height: 70px;
}
.header .logo {
    float: left;
    width: 250px;
    line-height: 70px;
    text-align: center;
}
.header-right {
    float: right;
    padding-right: 50px;
}
.header-user-con {
    display: flex;
    height: 70px;
    align-items: center;
}
.btn-fullscreen {
    transform: rotate(45deg);
    margin-right: 5px;
    font-size: 24px;
}
.btn-bell,
.btn-fullscreen {
    position: relative;
    width: 30px;
    height: 30px;
    text-align: center;
    border-radius: 15px;
    cursor: pointer;
}
.btn-bell-badge {
    position: absolute;
    right: 0;
    top: -2px;
    width: 8px;
    height: 8px;
    border-radius: 4px;
    background: #f56c6c;
    color: #fff;
}
.btn-bell .el-icon-bell {
    color: #fff;
}
.user-name {
    margin-left: 10px;
}
.user-avator {
    margin-left: 20px;
}
.user-avator img {
    display: block;
    width: 40px;
    height: 40px;
    border-radius: 50%;
}
.el-dropdown-link {
    color: #fff;
    cursor: pointer;
}
.el-dropdown-menu__item {
    text-align: center;
}

.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 220px;
}
.sidebar > ul {
    height: 100%;
}
</style>